<?php

require_once 'Basic.php';

class ModelTypeList {

  private $list;
  private $dbFail;
  
  public function __construct() {
    $this->list = new Report();
    $this->dbFail = false;
    $this->buildList();
  }
 
  private function buildList() {
    $db = new DBUtils();
    
    try {
      $db->connect();
      $db->runQuery("select nome from TipoModelo");
      for($item = $db->getItem(); $item !== null; $item = $db->getItem()) {
        $listItem = new ReportItem("-");
        $listItem->addLine("Tipo", $item->nome);
  
        $this->list->addItem($listItem);
      }
      $db->close(true);
    }
    catch(DBError $e) {
      $db->close();
      $this->dbFail = true;
      logMessage($e, "ModelTypeList");
    }
  }
 
  public function getHtml() {
    if($this->dbFail) {
      return "<p>Falha ao acessar o banco de dados. O erro foi reportado.</p>";
    }
    else {
      return $this->list->getHtml();
    }
  }
  
}

mustBeEmployee();
$list = new ModelTypeList();
$page = new Page("Listagem de Tipos de Ve&iacute;culos");
$page->addContent($list->getHtml());
echo $page->getHtml();
  